package com.computergames.server.server.handler;

import com.computergames.server.message.AcknowledgeMessage;
import com.computergames.server.service.Interface.HandleAcknowledgeMessage;
import com.computergames.server.util.SpringUtil;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.AttributeKey;

@ChannelHandler.Sharable
public class AcknowledgeMessageHandler extends SimpleChannelInboundHandler<AcknowledgeMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext channelHandlerContext, AcknowledgeMessage msg) throws Exception {
        HandleAcknowledgeMessage handleAcknowledgeMessage = SpringUtil.getBean(HandleAcknowledgeMessage.class);
        String roomName = (String)channelHandlerContext.attr(AttributeKey.valueOf("USER_ROOM")).get();
        handleAcknowledgeMessage.handleAcknowledgeMessage(roomName, msg);
    }
}
